package com.stylefeng.guns.rest.modular.wz.api.v3.dao;

import com.stylefeng.guns.rest.common.persistence.dao.WzAdvMapMapper;
import com.stylefeng.guns.rest.common.persistence.dao.WzAdvMapper;
import com.stylefeng.guns.rest.common.persistence.dao.WzUserFinanceRecordMapper;
import com.stylefeng.guns.rest.common.persistence.dao.WzUserMapper;
import com.stylefeng.guns.rest.common.persistence.model.*;
import com.stylefeng.guns.rest.domain.Res;
import com.stylefeng.guns.rest.modular.wz.service.impl.WzUserAdvServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 地图广告数据保存类
 */
@Service
public class WzAdvMapDaoImpl {

    @Autowired
    private WzUserMapper userMapper;
    @Autowired
    private WzAdvMapMapper advMapMapper;
    @Autowired
    private WzUserFinanceRecordMapper userFinanceRecordMapper;
    @Autowired
    private WzUserAdvServiceImpl userAdvService;
    @Autowired
    private WzAdvMapper advMapper;

    @Transactional
    public Boolean saveSetTopAdvMapNew(WzUserFinanceRecord userFinanceRecord, WzUser user, WzAdvMap advMap, WzAdvMap advMapTemp) {
        int r = userMapper.updateById(user);
        if (r > 0) {
            r = advMapMapper.updateById(advMap);
            if (r > 0) {
                r = advMapMapper.insert(advMapTemp);
                if (r > 0) {
                    r = userFinanceRecordMapper.insert(userFinanceRecord);
                    if (r > 0) {
                        return true;
                    }
                }
                return true;
            }
        }
        return false;
    }

    @Transactional
    public boolean advMapEdit(WzAdvMap advMapTemp, WzAdvMap advMap) {
        int r = advMapMapper.updateById(advMap);
        if (r  > 0) {
            r = advMapMapper.insert(advMapTemp);
            if(r  > 0){
                return true;
            }
        }
        return false;
    }
}
